import {defaultAxios as request } from '@/utils/http/index.js';
var api = "/rtdb/api/v1";

// export const userRegister = (data) => {
//   return request({
//     url: '/showDatabase',
//     method: 'post',
//     data,
//   });
// };
export function addSuperTable(data = {},timeout=12000) {
  return request({
    url: api + '/addSuperTable',
    method: 'post',
    data,
    timeout: timeout 
  });
}

export function initTiTable(data = {},timeout=120000) {
  return request({
    url: api + '/initTiTable',
    method: 'post',
    data,
    timeout: timeout 
  });
}

export function initTnTable(data = {},timeout=120000) {
  return request({
    url: api + '/initTnTable',
    method: 'post',
    data,
    timeout: timeout 
  });
}

export function convertTnTable(data = {},timeout=120000) {
  return request({
    url: api + '/convertTnTable',
    method: 'post',
    data,
    timeout: timeout 
  });
}


/**
 * 创建超级表
 */
export function addCustomSuperTable(data,timeout=12000){
	return request({
    url: api + '/addCustomSuperTable',
    method: 'post',
    data,
    timeout: timeout 
  });
}

/**
 * 创建普通表
 */
export function addCustomTable(data,timeout=12000){
	return request({
    url: api + '/addCustomTable',
    method: 'post',
    data,
    timeout: timeout 
  });
}
/**
 * 获取表结构
 */
export function getTableStructure(data,timeout=12000){
	return request({
    url: api + '/getTableStructure',
    method: 'post',
    data,
    timeout: timeout 
  });
}

/**
 * 修改表
 */
export function alterTable(data,timeout=12000){
	return request({
    url: api + '/alterTable',
    method: 'post',
    data,
    timeout: timeout 
  });
}

/**
 * 创建数据库
 */
export function createDatabase(data,timeout=12000){
	return request({
    url: api + '/createDatabase',
    method: 'post',
    data,
    timeout: timeout 
  });
}


export function addChildTable(data,timeout=12000){
	return request({
    url: api + '/addChildTable',
    method: 'post',
    data,
    timeout: timeout 
  });
}

export function showDatabases(data = {},timeout=120000) {
  return request({
    url: api + '/showDatabases',
    method: 'get',
    params: data,
    timeout: timeout
  });
}


export function showTables(data = {},timeout=120000) {
  return request({
    url: api + '/showTables',
    method: 'get',
    params: data,
    timeout: timeout
  });
}

/**
 * 分页查询表格 
 * 支持名称过滤 查询指定超表的子表 分页
 */
export function getTableByPage(data,timeout=120000) {
  return request({
    url: api + '/getTableByPage',
    method: 'post',
    data,
    timeout: timeout
  });
}


export function showTablesBySTable(data = {},timeout=120000) {
  return request({
    url: api + '/showTablesBySTable',
    method: 'get',
    params: data,
    timeout: timeout
  });
}

/**
 * 获取超级表列表
 * @param {*} data 
 * @param {*} timeout 
 * @returns 
 */
export function showSTables(data = {},timeout=20000) {
  return request({
    url: api + '/showSTables',
    method: 'get',
    params: data,
    timeout: timeout
  });
}

/**
 * 获取表数据
 * 查询条件包括：表名、数据库名、开始时间、结束时间、时间间隔、排序、分页
 * @param {*} data
 * @param {*} timeout
 */
export function queryHistoryData(data = {},timeout=20000) {
  return request({
    url: api + '/queryHistoryData',
    method: 'post',
    data,
    timeout: timeout
  });
}

export function deleteTable(data = {}, timeout = 20000){
	return request({
		url: api + '/deleteTable',
    method: 'post',
    data,
    timeout: timeout
	})
}

/**
 * 执行sql
 * @param {*} data 
 * @param {*} timeout 
 * @returns 
 */
export function executeSQL(data = {},timeout=12000) {
  return request({
    url: api + '/executeSQL',
    method: 'post',
    data,
    timeout: timeout 
  });
}

export function getNodesInfo(data = {}, timeout = 20000){
	return request({
		url: api + '/getNodesInfo',
    method: 'post',
    data,
    timeout: timeout
	})
}


export function addNode(data = {}, timeout = 60000){
	return request({
		url: api + '/addNode',
    method: 'post',
    data,
    timeout: timeout
	})
}


export function deleteNode(data = {}, timeout = 60000){
	return request({
		url: api + '/deleteNode',
    method: 'post',
    data,
    timeout: timeout
	})
}


export function getSlowSqlByPage(data = {}, timeout = 20000){
	return request({
		url: api + '/getSlowSqlByPage',
    method: 'post',
    data,
    timeout: timeout
	})
}


export function getStatisticalSlowSqlByPage(data = {}, timeout = 20000){
	return request({
		url: api + '/getStatisticalSlowSqlByPage',
    method: 'post',
    data,
    timeout: timeout
	})
}

export function updateTsValue(data = {}, timeout = 20000){
	return request({
		url: api + '/updateTsValue',
    method: 'post',
    data,
    timeout: timeout
	})
}
